<template>
  <div class="container">
    <!-- 顶部区域 -->
    <div class="info-box">
      <van-image
        round
        width="65px"
        height="65px"
        fit="cover"
        :src="userInfo.photo"
      />
      <h2>
        {{ userInfo.name }}
        <br />
        <van-tag color="#fff" text-color="#2196f3" size="medium">
          {{ userInfo.birthday }}
        </van-tag>
      </h2>
    </div>
    <!-- 领行栏 -->
    <van-row class="user-nav">
      <van-col span="8"
        ><van-icon name="newspaper-o" color="#0098fa" size="20" /><br />
        我的作品</van-col
      >
      <van-col span="8"
        ><van-icon name="star-o" color="#ff583b" size="20" /><br />
        我的收藏</van-col
      >
      <van-col span="8"
        ><van-icon name="tosend" color="#ffa704" size="20" /><br />
        阅读历史</van-col
      >
    </van-row>
    <!-- cell列表 -->
    <van-cell-group>
      <van-cell title="编辑资料" is-link icon="edit" />
      <van-cell title="小智同学" is-link icon="chat-o" />
      <van-cell title="系统设置" is-link icon="setting-o" />
      <van-cell
        title="退出登录"
        is-link
        icon="warning-o"
        @click="logoutClick"
      />
    </van-cell-group>
  </div>
</template>

<script>
// 导入中间网络层
import { getUserInfo } from './user.js'
import { removeToken } from '@/utils/token.js'
export default {
  name: 'user',
  data () {
    return {
      userInfo: {}
    }
  },
  // 生命钩子
  created () {
    getUserInfo().then(res => {
      console.log(res)
      this.userInfo = res.data.data
    })
  },
  methods: {
    // 退出登录
    logoutClick () {
      this.$dialog.confirm({
         title: '您确定要退出嘛',
        message: '退出我是嫩爹'
      }).then(()=>{
        //清除token
        removeToken()
        // 清除用户数据
        this.userInfo = {}
        // 跳转到首页
        this.$router.push({path:'/login'})
      })
    }
  }
}
</script>

<style lang="less">
.container {
  // 顶部栏
  .info-box {
    height: 100px;
    background-color: pink;
    display: flex;
    align-items: center;
    h2 {
      font-size: 16px;
      color: #fff;
    }
    .van-image {
      padding: 15px;
    }
  }
  // 领行栏
  .user-nav {
    font-size: 16px;
    text-align: center;
    margin-bottom: 10px;
    // display: flex;
    // align-content: center;
    .van-icon {
      margin-top: 10px;
    }
  }
  // cell列表
}
</style>
